/* jshint esversion: 6 */
$(document).ready(function() {
    $('#captcha').on('click', getCaptcha);
    $('#getRegVerfCode').on('click', function() {
        let imgCaptcha = $('#imgCaptcha').val(); // 获取图形验证码input的值
        let phone = $('.cellPhoneNum').val(); // 获取手机号input的值
        ajaxXHR('post', url + 'v1/sms/captcha', function(data) {
            if (data.code == "sms_captcha_has_sent") {
                showCapthca('register');
            }
        }, {
            phone: phone,
            type: "login",
            imgCaptcha: imgCaptcha
        });
    });
    $('#regSubmit').on('click', function() {
        let phone = $('#regCellPhoneNum').val(); // 获取手机号input的值
        let smsCaptcha = $('#verfRegCode').val(); // 获取短信验证码input的值
        let password = $('#passwordReg').val(); // 获取密码input的值
        let password2 = $('#password2Reg').val(); // 获取密码input的值
        if (phone == "") {
            $('.modal-body').html('手机号不能为空!');
            $('.modal').modal('show');
            return;
        } else if (!(/^1[3|4|5|7|8]\d{9}$/.test(phone))) {
            $('.modal-body').html('不是完整的11位手机号或者正确的手机号前七位!');
            $('.modal').modal('show');
            return false;
        } else if (password != password2) {
            $('#passwordReg')[0].focus();
            return false;
        }
        ajaxXHR('post', url + 'v1/account/register', function(data) {
            localStorage.APISHotelname = data.data.account.name;
            localStorage.APISHoteltoken = data.data.account.token;
            localStorage.APISHotelid = data.data.account.id;
            $('.modal-body').html('注册成功!<a href="index.html">去首页</a>');
            $('.modal').modal('show');
        }, {
            phone: phone,
            password: password,
            smsCaptcha: smsCaptcha
        });
    });
    $('#tolog').on('click', function() {
        window.location.href = "login.html";
    });


})